#!/usr/bin/perl -w

# commify
# File ID: 895db0b6-5d37-11df-92d4-90e6ba3022ac
# Setter inn understrek i nummer.

use strict;
use Getopt::Std;

our $opt_s;

getopts('s:');

defined($opt_s) || ($opt_s = "_");

while (<>) {
	s/(\d{3,})/commify($1)/ge;
	print;
}

sub commify {
	my $Str = reverse $_[0];
	$Str =~ s/(\d\d\d)(?=\d)(?!\d*\,)/$1$opt_s/g;
	return scalar reverse $Str;
} # commify()
